package vcp.controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import vcp.application.UserManagement;
import vcp.common.AbstractController;
import vcp.common.IController;
import vcp.gui.forms.validators.NumericValidator;
import vcp.models.ParkingManagementModel;
import vcp.views.ParkingManagementView;

/**
 * ParkingManagement Controller
 * @author G15
 *
 */
public class ParkingManagementController extends AbstractController implements
		ActionListener, IController {
	ParkingManagementModel model;
	ParkingManagementView view;

	@Override
	public void addModel(Object model) {
		this.model = (ParkingManagementModel) model;
	}

	@Override
	public void addView(Object applicationView) {
		this.view = (ParkingManagementView) applicationView;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("ResetX")) {
			NumericValidator validator = new NumericValidator("\\d+");
			int lotVal = UserManagement.getInstance().getEmployee().getLotNo();
			if (!validator.validate(view.getParkingManagementForm()
					.getTextReset().getText())
					&& lotVal != 0) {
				JOptionPane.showMessageDialog(null, "Wrong input ... ",
						"Error", JOptionPane.ERROR_MESSAGE);
			} else {
				int newX = Integer.parseInt(view.getParkingManagementForm()
						.getTextReset().getText());

				ArrayList<Object> arr = new ArrayList<Object>();
				arr.add(lotVal);
				arr.add(newX);
				model.resetX(arr);
			}

		}
	}

}
